package com.ysd.modules.app.controller;

import com.ysd.common.utils.R;
import com.ysd.modules.app.entity.ChapterEntity;
import com.ysd.modules.app.entity.TestPaper;
import com.ysd.modules.app.entity.TopicEntity;
import com.ysd.modules.app.service.TestPapersService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author ky
 * @Date 2021/07/19
 * 试卷
 */
@RestController
@RequestMapping("/app")
@Api(description = "APP试卷接口")
public class AppTestPaperController {
    @Autowired
    private TestPapersService testPapersService;

    @GetMapping("getTestPapers")
    @ApiOperation("题库-模拟试题/考试测试(初始化)")
    @ApiResponses({
            @ApiResponse(code = 200, message = "OK", response = TestPaper.class)
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "courseId", value = "课程ID", paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "chapterId", value = "章节id(暂时传0)", paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "testMode", value = "(1:模拟试题 2:每日一练 3:自我测试 4:考试测试)", paramType = "query", dataType = "int"),
    })
    public R getTestPapers(Integer courseId, Integer chapterId, Integer testMode) {
        List<TestPaper> testPaperList = testPapersService.getTestPapers(courseId, chapterId, testMode);
        return R.ok().put("testPaperList", testPaperList);
    }

    @GetMapping("getTopicsByPid")
    @ApiOperation("题库-模拟试题-试卷试题")
    @ApiResponses({
            @ApiResponse(code = 200, message = "OK", response = TopicEntity.class)
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pid", value = "试卷ID", paramType = "query", dataType = "int"),
    })
    public R getTopicsByPid(Integer pid) {
        List<TopicEntity> topicEntityList = testPapersService.getTopicsByPid(pid);
        return R.ok().put("topicEntityList", topicEntityList);
    }

    @PostMapping("insert")
    @ApiOperation("每日一练/自我测试-试卷生成(废弃,使用其他接口)")
    public R insert(@RequestBody TestPaper testPaper) {
        return R.ok().put("res", testPapersService.insert(testPaper));
    }

    @GetMapping("getPaperDetails")
    @ApiOperation("试卷详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pid", value = "试卷ID", paramType = "query", dataType = "int"),
    })
    public R getPaperDetails(Integer pid) {
        Map<String, Object> paperDetails = testPapersService.getPaperDetails(pid);
        return R.ok().put("paperDetails", paperDetails);
    }

    @PostMapping("addPracticePaper")
    @ApiOperation("每日一练-组卷")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "courseId", value = "课程ID", paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "topicNum", value = "试题数量", paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "stuId", value = "学生ID", paramType = "query", dataType = "int"),
    })
    public R addPracticePaper(Integer courseId, Integer topicNum, Integer stuId) {
        return R.ok().put("res", testPapersService.addPaper("每日一练", courseId, topicNum, stuId, 2));
    }

    @PostMapping("addSelfPaper")
    @ApiOperation("自我测试-组卷")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "courseId", value = "课程ID", paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "topicNum", value = "试题数量", paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "stuId", value = "学生ID", paramType = "query", dataType = "int"),
    })
    public R addSelfPaper(Integer courseId, Integer topicNum, Integer stuId) {
        return R.ok().put("res", testPapersService.addPaper("自我测试", courseId, topicNum, stuId, 3));
    }

    @PostMapping("addExamPaper")
    @ApiOperation("考试测试-组卷")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "courseId", value = "课程ID", paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "topicNum", value = "试题数量", paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "stuId", value = "学生ID", paramType = "query", dataType = "int"),
    })
    public R addExamPaper(Integer courseId, Integer topicNum, Integer stuId) {
        return R.ok().put("res", testPapersService.addPaper("考试测试", courseId, topicNum, stuId, 4));
    }

    @GetMapping("getTopicsListByPaper")
    @ApiOperation("试卷试题")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "paperId", value = "试卷ID", paramType = "query", dataType = "int"),
    })
    public R getTopicsListByPaper(Integer paperId) {
        List<TopicEntity> topicEntityList = testPapersService.getTopicsListByPaper(paperId);
        return R.ok().put("topicEntityList", topicEntityList);
    }

}
